package com.disapand.strongarmy.model

import org.ktorm.database.Database
import org.ktorm.entity.Entity
import org.ktorm.entity.sequenceOf
import org.ktorm.schema.Table
import org.ktorm.schema.datetime
import org.ktorm.schema.int
import java.time.LocalDateTime

/**
 * 登录日志对象
 *
 * @auth disapand
 * @date 2021/10/12 - 21:47 - 星期二
 *
 */
interface LoginLog : Entity<LoginLog> {
    companion object: Entity.Factory<LoginLog>()

    val id: Int
    var accountId: Int
    var loginBy: Int
    var loginAt: LocalDateTime
}

/**
 * 登录日志表
 */
object LoginLogs : Table<LoginLog>("sa_login_log") {
    val id = int("id").primaryKey().bindTo { it.id }
    val accountId = int("account_id").bindTo { it.accountId }
    val loginBy = int("login_by").bindTo { it.loginBy }
    val loginAt = datetime("login_at").bindTo { it.loginAt }
}

val Database.loginLogs get() = this.sequenceOf(LoginLogs)